package com.itheima.server.controller;

import com.itheima.model.dto.QuestionsDto;
import com.itheima.model.vo.ReportVo;
import com.itheima.model.vo.TestSoulVo;
import com.itheima.server.interceptor.UserHolder;
import com.itheima.server.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/testSoul")
@RestController
public class TestSoulController {
    @Autowired
    private TestService testService;
    /*测灵魂-提交问卷*/
    @PostMapping
    public ResponseEntity testSoul(@RequestBody Map<String,List<QuestionsDto>> answers) {
        List<QuestionsDto> answers1 = answers.get("answers");
        Long res = testService.replyQuestion(answers1);
        return ResponseEntity.ok(res.toString());
//        return ResponseEntity.ok(null);
    }
    /*测灵魂-问卷列表*/
    @GetMapping
    public ResponseEntity getQuestion(){
        List<TestSoulVo> res=testService.testSoulList(UserHolder.getUserId());
        return ResponseEntity.ok(res);
    }
    /*测灵魂-查看结果*/
    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable Long id){
        ReportVo vo = testService.queryReport(id);
        return ResponseEntity.ok(vo);
    }
}
